<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Waiting for Long Operations &mdash; pywinauto 0.5.4 documentation</title>
    
    <link rel="stylesheet" href="_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '0.5.4',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="pywinauto 0.5.4 documentation" href="contents.html" />
    <link rel="next" title="Methods available to each different control type" href="controls_overview.html" />
    <link rel="prev" title="How To’s" href="HowTo.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="controls_overview.html" title="Methods available to each different control type"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="HowTo.html" title="How To’s"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="contents.html">pywinauto 0.5.4 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="waiting-for-long-operations">
<h1>Waiting for Long Operations<a class="headerlink" href="#waiting-for-long-operations" title="Permalink to this headline">¶</a></h1>
<p>A GUI application behaviour is often unstable and your script needs
waiting until a new window appears or an existing window is closed/hidden.
pywinauto can wait for a dialog initialization implicitly (with the default
timeout). There are few methods/functions that could help you to make
your code easier and more reliable.</p>
<div class="section" id="application-methods">
<h2>Application methods<a class="headerlink" href="#application-methods" title="Permalink to this headline">¶</a></h2>
<blockquote>
<div><ul class="simple">
<li><a class="reference external" href="code/pywinauto.application.html?highlight=WaitCPUUsageLower#pywinauto.application.Application.WaitCPUUsageLower">WaitCPUUsageLower</a> (new in pywinauto 0.5.2)</li>
</ul>
</div></blockquote>
<p>This method is useful for multi-threaded interfaces that allow a lazy
initialization in another thread while GUI is responsive and all controls
already exist and ready to use. So waiting for a specific window existence/state
is useless. In such case the CPU usage for the whole process indicates that a task
calculation is not finished yet.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">app</span><span class="o">.</span><span class="n">WaitCPUUsageLower</span><span class="p">(</span><span class="n">threshold</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span> <span class="c"># wait until CPU usage is lower than 5%</span>
</pre></div>
</div>
</div>
<div class="section" id="windowspecification-methods">
<h2>WindowSpecification methods<a class="headerlink" href="#windowspecification-methods" title="Permalink to this headline">¶</a></h2>
<p>These methods are available to all controls.</p>
<blockquote>
<div><ul class="simple">
<li><a class="reference external" href="code/pywinauto.application.html?highlight=Wait#pywinauto.application.WindowSpecification.Wait">Wait</a></li>
<li><a class="reference external" href="code/pywinauto.application.html?highlight=WaitNot#pywinauto.application.WindowSpecification.WaitNot">WaitNot</a></li>
</ul>
</div></blockquote>
<p>There is an example containing long waits: <a class="reference external" href="https://gist.github.com/vasily-v-ryabov/7a04717af4584cbb840f">install script for 7zip 9.20 x64</a>.</p>
<p>A <code class="docutils literal"><span class="pre">WindowSpecification</span></code> object isn&#8217;t necessarily related to an existing window/control.
It&#8217;s just a description namely a couple of criteria to search the window. The <code class="docutils literal"><span class="pre">Wait</span></code> method (if no any exception is raised)
can guarantee that the target control exists or even visible, enabled and/or active.</p>
</div>
<div class="section" id="functions-in-timings-module">
<h2>Functions in <code class="docutils literal"><span class="pre">timings</span></code> module<a class="headerlink" href="#functions-in-timings-module" title="Permalink to this headline">¶</a></h2>
<p>There are also low-level methods useful for any Python code.</p>
<blockquote>
<div><ul class="simple">
<li><a class="reference external" href="code/pywinauto.timings.html?highlight=WaitUntil#pywinauto.timings.WaitUntil">WaitUntil</a></li>
<li><a class="reference external" href="code/pywinauto.timings.html?highlight=WaitUntilPasses#pywinauto.timings.WaitUntilPasses">WaitUntilPasses</a></li>
</ul>
</div></blockquote>
</div>
<div class="section" id="identify-controls">
<h2>Identify controls<a class="headerlink" href="#identify-controls" title="Permalink to this headline">¶</a></h2>
<p>The methods to help you to find a needed control.</p>
<blockquote>
<div><ul class="simple">
<li><a class="reference external" href="code/pywinauto.application.html?highlight=PrintControlIdentifiers#pywinauto.application.WindowSpecification.PrintControlIdentifiers">PrintControlIdentifiers</a></li>
<li><a class="reference external" href="code/pywinauto.controls.HwndWrapper.html?highlight=DrawOutline#pywinauto.controls.HwndWrapper.HwndWrapper.DrawOutline">DrawOutline</a></li>
</ul>
</div></blockquote>
<div class="section" id="how-to-s">
<h3>How To`s<a class="headerlink" href="#how-to-s" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="HowTo.html"><em>How To&#8217;s</em></a></li>
</ul>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Waiting for Long Operations</a><ul>
<li><a class="reference internal" href="#application-methods">Application methods</a></li>
<li><a class="reference internal" href="#windowspecification-methods">WindowSpecification methods</a></li>
<li><a class="reference internal" href="#functions-in-timings-module">Functions in <code class="docutils literal"><span class="pre">timings</span></code> module</a></li>
<li><a class="reference internal" href="#identify-controls">Identify controls</a><ul>
<li><a class="reference internal" href="#how-to-s">How To`s</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="HowTo.html"
                        title="previous chapter">How To&#8217;s</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="controls_overview.html"
                        title="next chapter">Methods available to each different control type</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/wait_long_operations.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="controls_overview.html" title="Methods available to each different control type"
             >next</a> |</li>
        <li class="right" >
          <a href="HowTo.html" title="How To’s"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="contents.html">pywinauto 0.5.4 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &copy; Copyright 2015, Mark Mc Mahon.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.1.
    </div>
  </body>
</html>